package com.example.demo.componet;

import com.example.demo.model.BrandJson;
import org.apache.spark.sql.sources.In;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 将wordcount的map类型转为java bean 类型  {name= null,value = null }
 *
 * @author xwh
 * @date 2023/02/03
 */

@Component
public class WordCountMapBean {

    public WordCountMapBean(){

    }

    public List<BrandJson> makeWordCountBean(Map<String, Integer> map){
        List<BrandJson> list = new ArrayList<>();

        for (Map.Entry<String,Integer> entry:map.entrySet()
        ) {

            BrandJson brandJson =new BrandJson();
            brandJson.setName(entry.getKey());
            brandJson.setValue(entry.getValue());

            list.add(brandJson);
        }

        return list;
    }

}
